package com.wzy.redisdemo.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wzy.redisdemo.pojo.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;

@CacheConfig(cacheNames = "users")
public interface UserMapper extends BaseMapper {

    @Cacheable(key = "#p0",value = "users")
    @Select("select * from user where name=#{userName} and password=#{password}")
    public User findLogin(@Param("userName") String userName,@Param("password") String password);

    @CachePut(key = "#p0")
    @Select("select * from user where id=#{id}")
    public User findById(@Param("id") String id);

    @CacheEvict(key = "#p0", allEntries = false)
    @Delete("delete from user where id=#{id}")
    public int deleteById(@Param("id") String id);
}
